#!/bin/sh

# ${bn}e${v1to2}xec dir of${fr}as progra${v2to1}sExec="/home/Gratis/krtkg27/Versions/GRATIS.12.7.2/PRODUCTION/src/gent/werner/Abas"

# fraction for interpolation
fr="-1"

bail()
{
        echo "Bailing out ..."
        exit 1
}

usage()
{
    echo "janus.sh <output directory> <the N th fraction>"
    echo "         <vectormap CT1 to CT2 basename> <vectormap CT2 to CT1 basename>"
    echo "         <CT1 directory> <CT1 fraction> <Plan1 directory> <plan1 number>"
    echo "         <CT2 directory> <CT2 fraction> <Plan2 directory> <plan2 number>"
    exit 1
}

wrong()
{
        echo "Something went wrong:"
        if [ "x$1" != "x" ]; then
                echo "$1"
        fi
}

# output directory
odir="$1"

# output on the N th fraction
nfr="$2"

# vectormap from CT1 to CT2
v1to2="$3"
v2to1="$4"

# first plan
i1="$5"
p1fr="$6"
p1="$7"
p1n="$8"

# second plan
i2="$9"
p2fr="${10}"
p2="${11}"
p2n="${12}"

# base name of the interpolated dataset
p1bn="not_used"

# $1 fraction for interpolated plan
fractionate()
{
    fr=`echo "($1-(${p1fr}))/(${p2fr}-(${p1fr}))"|bc -l`
    echo ${fr}
}

fractionate "${nfr}"

p1bn="${p1fr}.${nfr}"
i12ip="${p1fr}2${p1bn}"
p2bn="${p2fr}.${nfr}"
ip2i1="${p1bn}2${p1fr}


# create an mhd file at the interpolated fraction
interpolMhd "${p1bn}" "${v1to2}" `echo "(1-${fr})"|bc -l` "${v2to1}" "${fr}"

# interpolate vectormap from CT1 to CT2

